package cn.daichi.rabbitdemo.ttl.msgttl;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MsgTtlConfig {

    public static final String MSG_TTL_QUEUE = "msg_ttl_queue";
    public static final String MSG_TTL_EXCHANGE = "msg_ttl_exchange";
    public static final String MSG_TTL_ROUTING_KEY = "msg_ttl_routing_key";

    @Bean
    Queue msgTtlQueue() {
        return new Queue(MSG_TTL_QUEUE, true, false, false);
    }

    @Bean
    DirectExchange msgTtlDirectExchange() {
        return new DirectExchange(MSG_TTL_EXCHANGE, true, false);
    }

    @Bean
    Binding msgTtlBinding() {
        return BindingBuilder.bind(msgTtlQueue())
                .to(msgTtlDirectExchange())
                .with(MSG_TTL_ROUTING_KEY);
    }

}
